package com.dididoctor.doctor.WYY;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dididoctor.doctor.Activity.GlobalParams;
import com.dididoctor.doctor.Activity.Order.DiagnosisSuggest.DiagnosisSuggestActivity;
import com.dididoctor.doctor.Activity.Order.Inquiry.InquiryDetailsActivity;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.LoaderImage;
import com.dididoctor.doctor.Utils.SharedPreferencesUtils;
import com.dididoctor.doctor.Utils.UserHeadImage;
import com.netease.nim.uikit.session.viewholder.MsgViewHolderBase;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

/**
 * Created by zhoujianghua on 2015/8/4.
 */
public class MsgViewHolderGuess extends MsgViewHolderBase implements View.OnClickListener {

    private TextView tv_gusa_name, tv_gusa_age, tv_guse_disname, tv_guess_medical_click;
    private UserHeadImage img_userimg;
    private LoaderImage loaderImage;
    private String disId;
    private String recId;
    private String patientName;
    private String age;
    private String illName;
    private String sex;
    private String patientHeadPic;
    private RelativeLayout ll_medical;
    private Button btn_confirm;
    @Override
    protected int getContentResId() {
        return R.layout.item_gusa_medical;

    }

    @Override
    protected void inflateContentView() {
        loaderImage = new LoaderImage(GlobalParams.getContext());

        img_userimg = (UserHeadImage) view.findViewById(R.id.img_userimg);
        tv_gusa_name = (TextView) view.findViewById(R.id.tv_gusa_name);
        tv_gusa_age = (TextView) view.findViewById(R.id.tv_gusa_age);
        tv_guse_disname = (TextView) view.findViewById(R.id.tv_guse_disname);

        ll_medical = (RelativeLayout) view.findViewById(R.id.ll_medical);
        ll_medical.setOnClickListener(this);
        btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        btn_confirm.setOnClickListener(this);
    }

    @Override
    protected void setLayoutParams(int width, int height, View... views) {
        View ll_medical = view.findViewById(R.id.ll_medical);
//        setLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,ll_medical);
        super.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, ll_medical);
    }

    @Override
    protected void bindContentView() {
        GuessAttachment attachment = (GuessAttachment) message.getAttachment();
        disId = attachment.getDisId();
        recId = attachment.getRecId();
        patientName = attachment.getPatientName();
        age = attachment.getAge();
        illName = attachment.getIllName();
        sex = attachment.getSex();
        patientHeadPic = attachment.getPatientHeadPic();
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessdsiID", disId);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessRecId", recId);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuesspatientName", patientName);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "Guessage", age);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessillName", illName);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuesspatientHeadPic", patientHeadPic);
        loaderImage.load(img_userimg, attachment.getPatientHeadPic(), new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                img_userimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                img_userimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        tv_gusa_name.setText(attachment.getPatientName());
        tv_gusa_age.setText(attachment.getAge());
        tv_guse_disname.setText(attachment.getIllName());


    }


    @Override
    protected boolean onItemLongClick() {

        return false;
    }


    private void layoutByDirection() {
        View ll_medical = findViewById(R.id.ll_medical);
        View tv_guess_medical_click = findViewById(R.id.tv_guess_medical_click);

        ViewGroup container = (ViewGroup) ll_medical.getParent();
        container.removeView(tv_guess_medical_click);
        if (isReceivedMessage()) {
            container.addView(tv_guess_medical_click, 1);
        } else {
            container.addView(tv_guess_medical_click, 0);
        }
        if (message.getStatus() == MsgStatusEnum.success) {
        } else {
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_medical:
                if (message.getStatus() == MsgStatusEnum.success) {
                    Intent intent = new Intent(context, InquiryDetailsActivity.class);
                    intent.putExtra("recId", recId);
                    intent.putExtra("patientName", patientName);
                    intent.putExtra("age", age);
                    intent.putExtra("illName", illName);
                    intent.putExtra("patientHeadPic", patientHeadPic);
                    intent.putExtra("sex", sex);
                    context.startActivity(intent);
                }
                break;
            case R.id.btn_confirm:
                String accId = message.getFromAccount();
                Intent intetn = new Intent(Token.getMcontext(),DiagnosisSuggestActivity.class);
                intetn.putExtra("accId", accId);
                intetn.putExtra("recId", recId);
                intetn.putExtra("disId", disId);
                intetn.putExtra("patientName", patientName);
                intetn.putExtra("age", age);
                intetn.putExtra("illName", illName);
                intetn.putExtra("patientHeadPic", patientHeadPic);
                intetn.putExtra("sex", sex);
                context.startActivity(intetn);
                break;
        }

    }
}
